package com.example.togethermove.config;


import com.blankj.utilcode.util.SPUtils;
import com.example.togethermove.utils.SPUtilsone;
import com.example.togethermove.utils.StringUtilone;

import java.util.List;


//
public final class ConfigUtil {
    public static void setIsLogin(boolean isLogin) {
        SPUtilsone.putBooleanValue(Constants.login_state, isLogin);
        Config.isLogin = isLogin;
    }

    public static boolean isLogin() {
        boolean data = Config.isLogin;
        if (!data) {
            data = Config.isLogin = SPUtilsone.getBooleanValue(Constants.login_state, data);
        }
        return data;
    }

    public static boolean isLoginOut() {
        return !isLogin();
    }


    public static String getMemberId() {
        String temp = Config.memberId;
        if (temp.equals("")) {
            temp = SPUtilsone.getStringValue(Constants.memberId, temp);
        }
        return temp;
    }

//    public static void setMemberId(LoginRData.LoginMemberInfoBo bo) {
//        if (bo.getMemberId() != null) {
//            SPUtilsone.putStringValue(Constants.memberId, bo.getMemberId());
//        } else {
//            SPUtilsone.putStringValue(Constants.memberId, "");
//        }
//        if (bo.getUsername() != null) {
//            SPUtilsone.putStringValue(Constants.username, bo.getUsername());
//        } else {
//            SPUtilsone.putStringValue(Constants.username, "");
//        }
//        if (bo.getMobile() != null) {
//            SPUtilsone.putStringValue(Constants.mobile, bo.getMobile());
//        } else {
//            SPUtilsone.putStringValue(Constants.mobile, "");
//        }
//
//        setUserPhoto(bo.getProfilePath());
//    }

    public static void setUserName(String userName) {
        if (!StringUtilone.isNull(userName)) {
            SPUtilsone.putStringValue(Constants.username, userName);
        }
    }

    public static String getUsername() {
        String temp = Config.memberId;
        if (temp.equals("")) {
            temp = SPUtilsone.getStringValue(Constants.username, temp);
        }
        return temp;
    }

    public static void setWechatCode(String code) {
        if (!StringUtilone.isNull(code)) {
            SPUtilsone.putStringValue(Constants.username, code);
        }
    }

    public static String wechatCode() {
        String temp = "";
        if (temp.equals("")) {
            temp = SPUtilsone.getStringValue(Constants.wechatCode, temp);
        }
        return temp;
    }

    public static String inviteCode() {
        String temp = "";
        if (temp.equals("")) {
            temp = SPUtilsone.getStringValue(Constants.inviteCode, temp);
        }
        return temp;
    }

    public static void setUserPhoto(String userName) {
//        if (!SPUtilsone.isNull(userName)) {
//            SPUtilsone.putStringValue(Constants.userphoto, userName);
//        }
    }

    public static String getUserPhoto() {
        String temp = Config.memberId;
        if (temp.equals("")) {
            temp = SPUtilsone.getStringValue(Constants.userphoto, temp);
        }
        return temp;
    }

    public static String getMobile() {
        String temp = Config.memberId;
        if (temp.equals("")) {
            temp = SPUtilsone.getStringValue(Constants.mobile, temp);
        }
        return temp;
    }


//
//
//
//    public static boolean showMemberImg() {
//        try {
//            return isLogin() && !StringUtil.isNull(getMemberInfo().getHeadPhotoUrl());
//        } catch (Exception e) {
//
//        }
//        return false;
//
//    }


    /**
     * 身份证号加** 显示 格式为1234****2018
     *
     * @return
     */
    public static String getStartedIdNum() {
        try {
            String idCard = "";
//            String idCard = getMemberInfo().getIdCard();
            if (StringUtilone.isNull(idCard))
                return "-";
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(idCard.substring(0, 4))
                    .append("****")
                    .append(idCard.substring(idCard.length() - 4, idCard.length()));
            return stringBuilder.toString();
        } catch (Exception e) {

        }
        return "-";
    }


    public static void saveTimeAndId(String today, String videoId) {//保存当前id及时间
        String strid = SPUtilsone.getStringValue(Constants.videoId, "");
        if (SPUtilsone.getStringValue(Constants.today, "").equals(today)) {
            if (!strid.equals("")) {
                if (!strid.contains(videoId)) {
                    strid = strid + "," + videoId;
                }
            } else {
                strid = videoId;
            }
            SPUtilsone.putStringValue(Constants.videoId, strid);
        } else {//时间不相同 保存  并把list 清除了
            SPUtilsone.putStringValue(Constants.today, today);
            SPUtilsone.putStringValue(Constants.videoId, videoId);
        }
    }
    public static boolean hasVideoId(String id) {

        return false;
    }
    public static List<String> getVideoId() {
        List<String> jsonbean = null;
        try {
//            jsonbean = JsonUtils.deserialize(SPUtils.getStringValue(Constants.citylist, ""), );
        } catch (Exception e) {
            e.printStackTrace();
        }
        return jsonbean;
    }


}
